<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>培训文件列表页面</title>
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>
<script type="text/javascript" src="${basePath}/js/jquery.Huploadify.js"></script>
	<link href="${basePath}/css/Huploadify.css" rel="stylesheet">
	<style>
	table label.error {
		margin-left: 5px;
		width: auto;
		display: inline;
		color: red;
	}
	
	table tr td{color:black;}
	.textat {text-align: center;}
	</style>
	<script type="text/javascript">
 //图片上传
        var file_path = "prefix";
        var file_path_one = null;
        var fileMap = new Array();
        $(function(){
            var up = $('#uploadadd').Huploadify({
                auto:false,
                fileTypeExts:'*.*',
                multi:true,
                formData:{key:123456,key2:'vvvv'},
                fileSizeLimit:99999999999,
                showUploadedPercent:true,
                showUploadedSize:true,
                removeTimeout:9999999,
                uploader : '${basePath}/trainingDoc/source_upload',
                onUploadStart:function(file){
                    console.log(file.name+'开始上传');
                },
                onInit:function(obj){
                    console.log('初始化');
                    console.log(obj);
                },
                onUploadComplete:function(file,data){
                    debugger;
                    var fi = $.parseJSON(data);
                    //文件名称
                    var filename = fi.filename;
                    //生成后的文件名
                    var sysFilepath = fi.sysfilepath;
                    //文件路径
                    var filepath = fi.filepath;
                    file_path_one = filename + "," + filepath;
                    file_path = file_path+"|"+filepath;
                    up.filePath=file_path_one;
                    //保存到集合
                    fileMap[file.index]=new Array(file_path_one);
                },
                onCancel:function(file){
                    console.log(file.name+'删除成功');
                },
                onClearQueue:function(queueItemCount){
                    console.log('有'+queueItemCount+'个文件被删除了');
                },
                onDestroy:function(){
                    console.log('destroyed!');
                },
                onSelect:function(file){
                    console.log(file.name+'加入上传队列');
                },
                onQueueComplete:function(queueData){
                    console.log('队列中的文件全部上传完成',queueData);
                }
            });
            
          //设置固定活动日弹出层
            $("#div1").dialog({
                width : '450px',
                height : 'auto',
                bgiframe : true,
                modal : true,
                draggable : true,
                resizable : false,
                title : '上传文件',
                autoOpen : false,
                buttons : {
                    '取消' : function() {
                        $(this).dialog('close');
                    },
                    '确定' : function() {
                    	if($("#keyWords1").val() == "" ){
                    		alert('关键字不能为空');
                    		return;
                    	}
                    	if($("#fileType1").val() == "" ){
                    		alert('类别不能为空');
                    		return;
                    	}
                        $.ajax({
                            type: "GET",
                            url: "${basePath}/trainingDoc/save?keyWords1="+$("#keyWords1").val()+"&fileType1="+$("#fileType1").val(),
                            dataType: "json",
                            success: function(data){
                                if(data==1){
                                    //alert('上传成功');
                                    $("#keyWords1").attr("value","");
                                    $("#fileType1").attr("value","");
                                    $('#dg').datagrid('load', {
    									fileName : $('#fileName').val(),
    									keyWords : $("#keyWords").val(),
    									fileType : $("#fileType").val(),
    									startTime : $("#startTime").val(),
    									endTime : $("#endTime").val()
    									
    								}); 
                                	window.location.reload();
                                    
                                    
                                }else{
                                    alert('上传失败，请联系管理员');
                                }
                            },
                            complete: function(){
                                $("#div1").dialog('close');
                                
                                $('#uploadadd').html("");


                            }
                        });
                    }
                }
            });

            //点击弹出层
            $("#daySet").click(function(){
                $('#div1').dialog('open');
            });
            
            
        });
        
        
        
      //删除图片
        function deletefile(id){
            var url = "${basePath}/trainingDoc/deletefile";
            $.ajax({
                type : "POST",
                url : url,
                dataType:"json",
                data:{
                    filepath : id
                },
                success : function(data) {
                    if(data.success == "0000"){
                        alert("删除数据成功！");
                        var file_name = id.split(",")[0];
                        $("#"+file_name+"_hr").parent().parent().remove();
                    }
                }
            })
        }
        </script>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
		<input type="hidden" name="idList" id="idList" />
		<%@ include file="/module/orderField.jsp"%>
		<table cellpadding="1" cellspacing="1" border="0">
			<tr>
				<td><input type="button" id="btnQuery" value="查 询"
					class="inputButton" /></td>
					
				 <kl:permission permisstionList="${permisstionList}"
					currentUser="${_login_console_user}"
					currentCatalogId="<%=CatalogUtils.getCatalogId(\"JKY_JYPX_PXWJ\")%>"
					key="add">
					<td><input type="button" id="daySet" value="上传文件"
						class="inputButton" /></td>
				 </kl:permission>
				
				 <kl:permission permisstionList="${permisstionList}"
					currentUser="${_login_console_user}"
					currentCatalogId="<%=CatalogUtils.getCatalogId(\"JKY_JYPX_PXWJ\")%>"
					key="delete">
				<td><input type="button" id="btnDelete" value="删除文件"
					class="inputButton" /></td>
					 </kl:permission>
					
			</tr>
		</table>
		<table cellpadding="1" cellspacing="1">
			<tr>
				<td>文件名：</td><td><input type="text" name="fileName"  id="fileName"  value="" 	class="inputText2" /></td>
				<td>关键字：</td><td><input type="text" name="keyWords"  id="keyWords"  value="" 	class="inputText2" /></td>
				<td>类别：</td><td><input type="text" name="fileType"  id="fileType"  value="" 	class="inputText2" /></td>
				<td>
                 上传日期：   从
                    <input name="startTime" id="startTime"  autocomplete="off"
                           class="Wdate required inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
                    到
                    <input name="endTime" id="endTime" autocomplete="off"
                           class="Wdate required inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
                </td>
			</tr>
		</table>
		<br />
		<table id="dg" style="width: 100%;"
			data-options="pagination:true,collapsible:true,url:'${basePath}/trainingDoc/list',method:'post',remoteSort:true">
			<thead>
				<tr>
					<th
						data-options="field:'fileId',checkbox:true,width:80,align:'center'"></th>
					<th
						data-options="field:'fileName',nowrap:true,width:200,align:'center',sortable:true,formatter:go2Info">文件名</th>
					<th
						data-options="field:'fileSize',nowrap:true,width:150,align:'center',sortable:true">文件大小</th>
					<th
						data-options="field:'fileType',nowrap:true,width:200,align:'center',sortable:true">类别</th>
					<th
						data-options="field:'creatorName',nowrap:true,width:200,align:'center',sortable:true">创建人</th>
					<th
						data-options="field:'createTime',nowrap:true,width:200,align:'center',sortable:true">创建时间</th>
				</tr>
			</thead>
		</table>
		
		<div id="div1" style="display: none;">
            <table cellpadding="0" style="padding-top: 20px;table-layout:fixed;" cellspacing="0" border="0" class="table-border" width="95%">
                <tr>
					<td  class="table-titleTD" style="width: 52px;">关键字：</td>
					<td  class="table-contentTD"><input type="text" name="keyWords1"  id="keyWords1"  value="" 	class="inputText" /></td>
				 </tr>
				 <tr>
					<td  class="table-titleTD">类别：</td>
					 <td  class="table-contentTD"><input type="text" name="fileType1"  id="fileType1"  value="" 	class="inputText" /></td>
                </tr>
                <tr>
                	<td  class="table-titleTD">文件：</td>
					<td  class="table-contentTD"><div id="uploadadd"></div></td>
                	 
                </tr>
                <!-- <tr>
                	<td><input type="button" id="btnUploadOK" value="上传" class="inputButton" /></td>
                </tr> -->
            </table>
        </div>
	</form>
	<script type="text/javascript">
		$(document)
				.ready(
						function() {

							$('#dg')
									.datagrid(
											{
												rowStyler : function(index, row) {
												},
												onLoadSuccess : function(data) {//加载完毕后获取所有的checkbox遍历
													if (data.rows.length > 0) {
													}
												},
											});
							//查询
							$('#btnQuery').click(function() {
								$('#dg').datagrid('load', {
									fileName : $('#fileName').val(),
									keyWords : $("#keyWords").val(),
									fileType : $("#fileType").val(),
									startTime : $("#startTime").val(),
									endTime : $("#endTime").val()
									
								});
							});
							$('#easyui-ck').click(function() {
								var data = $("#dg").datagrid("getSelections");
								for (var i = 0; i < data.length; i++) {
								}
							});
							
 
							$('#btnDelete')
									.click(
											function() {
												$("#idList").val("");
												var count = 0;
												var idList = new Array();
												var sels = $("#dg").datagrid(
														"getSelections");
												for ( var i in sels) {
													idList.push(sels[i].fileId);
													count++;
												}

												if (count == 0) {
													layer.alert(
															"您至少选择一条删除记录信息", {
																icon : 3
															});
													return false;
												} else {
													layer
															.confirm(
																	"您是否删除当前选中数据信息",
																	{
																		icon : 3,
																		title : '提示',
																		skin : 'layer-ext-moon'
																	},
																	function(
																			index) {
																		$(
																				"#idList")
																				.val(
																						idList);
																		document.Form.action = "${basePath}/trainingDoc/delete";
																		document.Form
																				.submit();
																	},
																	function(
																			index) {
																		layer
																				.close(index);
																	});
												}
											});
						});
		if ("${msg}" != "") {
			layer.alert("${msg}", {
				icon : 6
			});
		}

		function go2Info(value,row, index) {

			return "<a href='${basePath}/DownLoadFileServlet?filename="+row.fileName+"&filepath="+row.filePath+"'>" + value + "</a>";
		}
	</script>
</body>
</html>
